package cn.com.dragonsoftbravo.utils;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MailUtils {

	private static ApplicationContext context = new ClassPathXmlApplicationContext(
			"classpath*:application-utils.xml");

	public static void sendMails(final String emailAddr, final String mailTitle, final String mailConcept) {

		Thread t = new Thread(new Runnable() {
			public void run() {
				BaseMailSender sender = (MailSenderImpl) context.getBean("mailSender");
				sender.sendMail(emailAddr, mailTitle, mailConcept);
			}
		});

		t.start();
	}

	/**
	 * 
	 * @param mailTitle
	 * @param mailConcept
	 */
	public static void sendMails(final List<String> mails, final String mailTitle, final String mailConcept) {

		Thread thread = new Thread(new Runnable() {
			private ApplicationContext context;

			public void run() {
				context = new ClassPathXmlApplicationContext("classpath*:application-utils.xml");
				BaseMailSender sender = (MailSenderImpl) context.getBean("mailSender");
				for (String mailAddr : mails) {
					sender.sendMail(mailAddr, mailTitle, mailConcept);
				}
			}
		});

		thread.start();

	}
}
